﻿// Decompiled with JetBrains decompiler
// Type: CreateMfgByCoordinates.CUiCreCreateMfgCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.CreateWeldPoint;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace CreateMfgByCoordinates;

public class CUiCreCreateMfgCmd : TxButtonCommand
{
  private CApCreCreateMfgEnabler m_enabler;
  private CUiCreCreateMfgTCForm _createWPbyCoordinatesTCForm;
  private ITxObject _prevWeldContainer;
  private ITxObject _prevWeldOperation;

  public CUiCreCreateMfgCmd() => this.m_enabler = new CApCreCreateMfgEnabler();

  public virtual string Category => this.GetResourceManager().GetString("CMD_CATEGORY");

  public virtual string Description => this.GetResourceManager().GetString("CMD_DESCRIPTION");

  public virtual string[] AdvancedDescriptions => TxCallMessages.CollectMessages((ITxCommand) this);

  public virtual string Name => this.GetResourceManager().GetString("CMD_NAME");

  public virtual string Bitmap => this.GetResourceManager().GetString("CMD_BITMAP");

  public virtual string Tooltip => this.GetResourceManager().GetString("CMD_TOOLTIP");

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual ITxImage Image
  {
    get => (ITxImage) TxImageManager.GetImageByKey("CreateWeldPointByCoordinates");
  }

  public virtual void Execute(object cmdParams)
  {
    if (TxTcUtilities.IsTcAnyPlatform)
    {
      this._createWPbyCoordinatesTCForm = new CUiCreCreateMfgTCForm();
      this.InitTCFormWithLastUsedObjects();
      ((Form) this._createWPbyCoordinatesTCForm).FormClosed += new FormClosedEventHandler(this._createWPbyCoordinatesTCForm_FormClosed);
      ((Control) this._createWPbyCoordinatesTCForm).Show();
    }
    else
      new CUiCreCreateMfgForm().Show(TxApplication.ActiveSelection.GetAllItems());
  }

  private ResourceManager GetResourceManager()
  {
    return new ResourceManager("DnProcessSimulateCommands.CreateMfgByCoordinates.StringTable", ((object) this).GetType().Assembly);
  }

  public virtual bool Licensed => TxCommandLicenser.CreateWeldPointByCoordinates;

  private void InitTCFormWithLastUsedObjects()
  {
    if (!CApCreateWpTCLogic.IsWpConfiguredAsPrivate() && this._prevWeldContainer != null && this._prevWeldContainer.IsValid())
      this._createWPbyCoordinatesTCForm.txebWeldContainer.Object = this._prevWeldContainer;
    if (this._prevWeldOperation == null || !this._prevWeldOperation.IsValid())
      return;
    this._createWPbyCoordinatesTCForm.txebWeldOperation.Object = this._prevWeldOperation;
  }

  private void _createWPbyCoordinatesTCForm_FormClosed(object sender, FormClosedEventArgs e)
  {
    if (((Form) this._createWPbyCoordinatesTCForm).DialogResult == DialogResult.Yes)
    {
      if (!CApCreateWpTCLogic.IsWpConfiguredAsPrivate())
        this._prevWeldContainer = this._createWPbyCoordinatesTCForm.txebWeldContainer.Object;
      this._prevWeldOperation = this._createWPbyCoordinatesTCForm.txebWeldOperation.Object;
    }
    this._createWPbyCoordinatesTCForm = (CUiCreCreateMfgTCForm) null;
  }
}
